package com.aoxin.controller.html;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.aoxin.model.SlfRecharge;
import com.aoxin.service.inter.opm.RechargeService;
import com.aoxin.util.AjaxRes;
import com.aoxin.util.Const;
import com.aoxin.util.enumerate.OperateType;
import com.aoxin.util.log.LogInfo;

@Controller
@ResponseBody
@RequestMapping("/web/recharge")
public class RechargeController {

	public static Integer recharge;

	@Autowired
	private RechargeService slfRechargeService;
	/**
	 * 充值记录查询
	 * 
	 * @param slfRecharge
	 * @param ajaxRes
	 */
	@RequestMapping("/getBySlfRecharge")
	@LogInfo(content = "用户充值", operateType = OperateType.QUERY)
	public AjaxRes getSlfRecharge(SlfRecharge slfRecharge, AjaxRes ajaxRes) {
		try {
			List<SlfRecharge> slfRecharges = slfRechargeService.getSlfRecharge(slfRecharge);
			ajaxRes.setSucceed(slfRecharges, Const.DATA_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 充值记录修改
	 * 
	 * @param slfRecharge
	 * @param ajaxRes
	 */
	@RequestMapping("/updateBySlfRecharge")
	@LogInfo(content = "用户充值", operateType = OperateType.UPDATE)
	public AjaxRes updateSlfRecharge(SlfRecharge slfRecharge, AjaxRes ajaxRes) {
		try {
			slfRechargeService.updateSlfRecharge(slfRecharge);
			ajaxRes.setSucceedMsg(Const.UPDATE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 充值记录添加
	 * 
	 * @param slfRecharge
	 * @param ajaxRes
	 */
	@RequestMapping("/insertBySlfRecharge")
	@LogInfo(content = "用户充值", operateType = OperateType.INSERT)
	public AjaxRes insertSlfRecharge(SlfRecharge slfRecharge, AjaxRes ajaxRes) {
		try {
			Integer recharge = slfRechargeService.insertSlfRecharge(slfRecharge);
			this.recharge = slfRecharge.getRecharge();
			System.out.println("recharge="+recharge);
			ajaxRes.setSucceed(recharge,Const.SAVE_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 充值记录批量删除
	 * 
	 * @param recharges
	 * @param ajaxRes
	 */
	@RequestMapping("/deleteByRecharge")
	@LogInfo(content = "用户充值", operateType = OperateType.DELETE)
	public AjaxRes deleteRecharge(List<Integer> recharges, AjaxRes ajaxRes) {
		try {
			slfRechargeService.deleteRecharge(recharges);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}

	/**
	 * 充值记录删除
	 * 
	 * @param recharge
	 * @param ajaxRes
	 */
	@RequestMapping("/deleteBySlfRecharge")
	@LogInfo(content = "用户充值", operateType = OperateType.DELETE)
	public AjaxRes deleteSlfRecharge(Integer recharge, AjaxRes ajaxRes) {
		try {
			slfRechargeService.deleteSlfRecharge(recharge);
			ajaxRes.setSucceedMsg(Const.DEL_SUCCEED);
		} catch (Exception e) {
			ajaxRes.setFailMsg(e.getMessage());
		}
		return ajaxRes;
	}
}
